package daoimpl;

import dao.DishDAO;
import model.Dish;
import org.hibernate.Transaction;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.slf4j.Logger;

import java.util.List;

/**
 * Created by admin on 2016/8/15.
 */

public class DishDAOImpl extends HibernateDaoSupport implements DishDAO {
    private static final Logger log = LoggerFactory.getLogger(DishDAOImpl.class);
    public Dish findById(int id) {
        log.debug("getting Dish instance with id: " + id);
        try {
            Dish instance = (Dish) getHibernateTemplate().get("model.Dish", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findAll() {
        log.debug("finding all Dish instances");
        try {
            String queryString = "from Dish";
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    @Override
    public void save(Dish dish) {
        getHibernateTemplate().saveOrUpdate(dish);
    }
}
